package com.itheima.web.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 响应字符数据:设置字符数据的响应体
 */
@WebServlet("/resp3")
public class ResponseDemo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;characters=UTF-8");
        //获取输出流
        PrintWriter writer = response.getWriter();
        //如果需要响应的是html文件就必须(content-type="text/html")
        response.setHeader("Content-type","text/html");
        writer.write("aaa");
        writer.write("<h1>aaa</h1>");

        /*细节:
        * 1.IO流不需要关闭资源
        * 2.默认流是ISO-8859-1,不是UTF-8格式;使用简化书写*/
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
